//
//  ForumHomeCell.m
//  JiaoX
//
//  Created by yinqy on 15/3/3.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "ForumHomeCell.h"

@interface ForumHomeCell()
{
    UIImageView *_imageView;
    UILabel *_titleLabel;
    UILabel *_descLabel;
    UIButton *_replyNumBtn;
}

@end
@implementation ForumHomeCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"forumhomecell";
    ForumHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[ForumHomeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 12.5, IMAGE_WIDTH, IMAGE_WIDTH)];
        [self addSubview:_imageView];
        _titleLabel = [[UILabel alloc]init];
        [_titleLabel setFont:[UIFont systemFontOfSize:[DimensUtils getScaleX:14]]];
        [_titleLabel setTextColor:JXColor(51, 51, 51)];
        [_titleLabel setFrame:CGRectMake(CGRectGetMaxX(_imageView.frame)+10, _imageView.y+2.5, JXScreenW-CGRectGetMaxX(_imageView.frame)-15, _titleLabel.font.lineHeight)];
        [self addSubview:_titleLabel];
        
        _replyNumBtn = [[UIButton alloc]init];
        [_replyNumBtn setTitleColor:JXColor(153, 153, 153) forState:UIControlStateNormal];
        [_replyNumBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        [_replyNumBtn setWidth:100];
        [_replyNumBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [_replyNumBtn setImage:[UIImage imageNamed:@"replyNum_icon"] forState:UIControlStateNormal];
        [_replyNumBtn.titleLabel setFont:[UIFont systemFontOfSize:[DimensUtils getScaleX:10]]];
        [_replyNumBtn setHidden:YES];
        [self addSubview:_replyNumBtn];
        
        _descLabel = [[UILabel alloc]init];
        [_descLabel setFont:[UIFont systemFontOfSize:[DimensUtils getScaleX:12]]];
        [_descLabel setNumberOfLines:2];
        [_descLabel setTextColor:JXColor(102, 102, 102)];
        [_descLabel setFrame:CGRectMake(_titleLabel.x, CGRectGetMaxY(_imageView.frame)-2.5-_descLabel.font.lineHeight*2, _titleLabel.width, _descLabel.font.lineHeight*2)];
        [self addSubview:_descLabel];
    }
    return self;
}

-(void)setBBSMode:(BBSModel *)model{
    [_imageView sd_setImageWithURL:[NSURL URLWithString:model.icon]];
    [_titleLabel setText:model.name];
    [_titleLabel sizeToFit];
    
    if (model.replyCount) {
        [_replyNumBtn setHidden:NO];
        [_replyNumBtn setX:CGRectGetMaxX(_titleLabel.frame)+10];
        [_replyNumBtn setTitle:[NSString stringWithFormat:@"%d",model.replyCount] forState:UIControlStateNormal];
        [_replyNumBtn sizeToFit];
        [_replyNumBtn setCenterY:_titleLabel.centerY];
        [_replyNumBtn setWidth:[_replyNumBtn.titleLabel.text sizeWithFont:_replyNumBtn.titleLabel.font].width+5+_replyNumBtn.imageView.image.size.width];
    }else{
        [_replyNumBtn setHidden:YES];
    }
    
    [_descLabel setText:model.modelDesc];
}

@end
